<template>
  <div class="newsinfo-container">
    <!--{{ $route.params.id}}-->
    <p class="news-title">{{newsInfo.title}}</p>
    <p class="sub-title">
      <span>时间：{{newsInfo.addTime|dateFormat('YYYY-MM-DD')}}</span>
      <span>点击：{{newsInfo.click}}次</span>
    </p>
    <hr>
    <div class="content" v-html="newsInfo.content"></div>
    <!--评论子组件-->
    <comment-box :id="this.id"></comment-box>
  </div>
</template>

<script>
//1.导入 评论子组件
import comment from "../subcomponents/comment.vue";
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      id: this.$route.params.id,
      newsInfo: {}
    };
  },
  created() {
    this.getnewsInfo();
  },
  methods: {
    getnewsInfo() {
      this.$http.get("newsInfo#!method=get").then(result => {
        if (result.status === 200) {
          this.newsInfo = result.body.message[0];
        } else {
          Toast("新闻获取失败");
        }
      });
    }
  },
  components: {
    "comment-box": comment
  }
};
</script>

<!--为了让内容里的图片能够是100%  要把 scoped 去了-->
<style lang="scss">
.newsinfo-container {
  padding: 10px 5px 0;
  .news-title {
    font-size: 14px;
    line-height: 30px;
    color: #333;
    text-align: center;
    margin: 0 auto;
  }
  .sub-title {
    font-size: 12px;
    line-height: 24px;
    color: #ddd;
    margin: 0 auto;
  }
  .content {
    font-size: 12px;
    line-height: 24px;
    img {
      max-width: 100%;
    }
  }
}
</style>